﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using elibrary.Classes;
using elibrary.Models.Managers;

namespace elibrary.Models.Entities
{
    public class BookCategory
    {
        /* Class Fields [Start] ----------------------------------------------------------------- */
        [Key]
        public int id { get; set; }
        public int bookId { get; set; }
        public int categoryId { get; set; }
        /* Class Fields [End] ------------------------------------------------------------------- */

        /* Computed Fields [Start] -------------------------------------------------------------- */
        public Book book
        {
            get { return this.getAssociatedBook(this.bookId); }
        }

        public Category category
        {
            get { return this.getAssociatedCategory(this.categoryId); }
        }

        public Dictionary<string,object> marketplaceObject
        {
            get { return this.getMarketplaceObject(); }
        }
        /* Computed Fields [End] ---------------------------------------------------------------- */

        private Book getAssociatedBook(int uid)
        {
            BookManager bookManager = new BookManager(AppGlobals.dataContext);

            return bookManager.get(uid);
        }

        private Category getAssociatedCategory(int uid)
        {
            CategoryManager categoryManager = new CategoryManager(AppGlobals.dataContext);
            
            return categoryManager.get(uid);
        }

        private Dictionary<string,object> getMarketplaceObject()
        {
            return this.category.marketplaceObject;
        }
    }
}